From: Salvatore Bonaccorso Date: Sun, 4 Feb 2024 20:02:11 +0000 (+0100) Subject: [PATCH 2/2] Revert "docs: kernel_feat.py: fix potential command injection" X-Git-Tag: archive/raspbian/6.12.27-1+rpi1^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2^2~23 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=7e65dd551db2c87327c351f8684138d8fd67947d;p=linux.git [PATCH 2/2] Revert "docs: kernel_feat.py: fix potential command injection" This reverts commit e961f8c6966abbd486ff87549e29e53f3c69b685. Gbp-Pq: Topic debian Gbp-Pq: Name Revert-docs-kernel_feat.py-fix-potential-command-inj.patch --- diff --git a/Documentation/admin-guide/features.rst b/Documentation/admin-guide/features.rst index 7651eca3822..8c167082a84 100644 --- a/Documentation/admin-guide/features.rst +++ b/Documentation/admin-guide/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features +.. kernel-feat:: $srctree/Documentation/features diff --git a/Documentation/arch/arc/features.rst b/Documentation/arch/arc/features.rst index 49ff446ff74..b793583d688 100644 --- a/Documentation/arch/arc/features.rst +++ b/Documentation/arch/arc/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features arc +.. kernel-feat:: $srctree/Documentation/features arc diff --git a/Documentation/arch/arm/features.rst b/Documentation/arch/arm/features.rst index 0e76aaf68ec..7414ec03dd1 100644 --- a/Documentation/arch/arm/features.rst +++ b/Documentation/arch/arm/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features arm +.. kernel-feat:: $srctree/Documentation/features arm diff --git a/Documentation/arch/arm64/features.rst b/Documentation/arch/arm64/features.rst index 03321f4309d..dfa4cb3cd3e 100644 --- a/Documentation/arch/arm64/features.rst +++ b/Documentation/arch/arm64/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features arm64 +.. kernel-feat:: $srctree/Documentation/features arm64 diff --git a/Documentation/arch/loongarch/features.rst b/Documentation/arch/loongarch/features.rst index 009f44c7951..ebacade3ea4 100644 --- a/Documentation/arch/loongarch/features.rst +++ b/Documentation/arch/loongarch/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features loongarch +.. kernel-feat:: $srctree/Documentation/features loongarch diff --git a/Documentation/arch/m68k/features.rst b/Documentation/arch/m68k/features.rst index de7f0ccf7fc..5107a211947 100644 --- a/Documentation/arch/m68k/features.rst +++ b/Documentation/arch/m68k/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features m68k +.. kernel-feat:: $srctree/Documentation/features m68k diff --git a/Documentation/arch/mips/features.rst b/Documentation/arch/mips/features.rst index 6e0ffe3e735..1973d729b29 100644 --- a/Documentation/arch/mips/features.rst +++ b/Documentation/arch/mips/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features mips +.. kernel-feat:: $srctree/Documentation/features mips diff --git a/Documentation/arch/nios2/features.rst b/Documentation/arch/nios2/features.rst index 89913810ccb..8449e63f69b 100644 --- a/Documentation/arch/nios2/features.rst +++ b/Documentation/arch/nios2/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features nios2 +.. kernel-feat:: $srctree/Documentation/features nios2 diff --git a/Documentation/arch/openrisc/features.rst b/Documentation/arch/openrisc/features.rst index bae2e25adfd..3f7c40d219f 100644 --- a/Documentation/arch/openrisc/features.rst +++ b/Documentation/arch/openrisc/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features openrisc +.. kernel-feat:: $srctree/Documentation/features openrisc diff --git a/Documentation/arch/parisc/features.rst b/Documentation/arch/parisc/features.rst index b3aa4d243b9..501d7c45003 100644 --- a/Documentation/arch/parisc/features.rst +++ b/Documentation/arch/parisc/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features parisc +.. kernel-feat:: $srctree/Documentation/features parisc diff --git a/Documentation/arch/s390/features.rst b/Documentation/arch/s390/features.rst index 2883dc95068..57c296a9d8f 100644 --- a/Documentation/arch/s390/features.rst +++ b/Documentation/arch/s390/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features s390 +.. kernel-feat:: $srctree/Documentation/features s390 diff --git a/Documentation/arch/sh/features.rst b/Documentation/arch/sh/features.rst index fae48fe81e9..f722af3b6c9 100644 --- a/Documentation/arch/sh/features.rst +++ b/Documentation/arch/sh/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features sh +.. kernel-feat:: $srctree/Documentation/features sh diff --git a/Documentation/arch/sparc/features.rst b/Documentation/arch/sparc/features.rst index 96835b6d598..c0c92468b0f 100644 --- a/Documentation/arch/sparc/features.rst +++ b/Documentation/arch/sparc/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features sparc +.. kernel-feat:: $srctree/Documentation/features sparc diff --git a/Documentation/arch/x86/features.rst b/Documentation/arch/x86/features.rst index a33616346a3..b663f15053c 100644 --- a/Documentation/arch/x86/features.rst +++ b/Documentation/arch/x86/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features x86 +.. kernel-feat:: $srctree/Documentation/features x86 diff --git a/Documentation/arch/xtensa/features.rst b/Documentation/arch/xtensa/features.rst index 28dcce1759b..6b92c7bfa19 100644 --- a/Documentation/arch/xtensa/features.rst +++ b/Documentation/arch/xtensa/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features xtensa +.. kernel-feat:: $srctree/Documentation/features xtensa diff --git a/Documentation/powerpc/features.rst b/Documentation/powerpc/features.rst index ee4b95e0420..aeae73df86b 100644 --- a/Documentation/powerpc/features.rst +++ b/Documentation/powerpc/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features powerpc +.. kernel-feat:: $srctree/Documentation/features powerpc diff --git a/Documentation/riscv/features.rst b/Documentation/riscv/features.rst index 36e90144ada..c70ef6ac236 100644 --- a/Documentation/riscv/features.rst +++ b/Documentation/riscv/features.rst @@ -1,3 +1,3 @@ .. SPDX-License-Identifier: GPL-2.0 -.. kernel-feat:: features riscv +.. kernel-feat:: $srctree/Documentation/features riscv diff --git a/Documentation/sphinx/kernel_feat.py b/Documentation/sphinx/kernel_feat.py index bdfaa3e4b20..27b701ed368 100644 --- a/Documentation/sphinx/kernel_feat.py +++ b/Documentation/sphinx/kernel_feat.py @@ -37,6 +37,8 @@ import re import subprocess import sys +from os import path + from docutils import nodes, statemachine from docutils.statemachine import ViewList from docutils.parsers.rst import directives, Directive @@ -74,26 +76,33 @@ class KernelFeat(Directive): self.state.document.settings.env.app.warn(message, prefix="") def run(self): + doc = self.state.document if not doc.settings.file_insertion_enabled: raise self.warning("docutils: file insertion disabled") env = doc.settings.env + cwd = path.dirname(doc.current_source) + cmd = "get_feat.pl rest --enable-fname --dir " + cmd += self.arguments[0] + + if len(self.arguments) > 1: + cmd += " --arch " + self.arguments[1] - srctree = os.path.abspath(os.environ["srctree"]) + srctree = path.abspath(os.environ["srctree"]) - args = [ - os.path.join(srctree, 'scripts/get_feat.pl'), - 'rest', - '--enable-fname', - '--dir', - os.path.join(srctree, 'Documentation', self.arguments[0]), - ] + fname = cmd - if len(self.arguments) > 1: - args.extend(['--arch', self.arguments[1]]) + # extend PATH with $(srctree)/scripts + path_env = os.pathsep.join([ + srctree + os.sep + "scripts", + os.environ["PATH"] + ]) + shell_env = os.environ.copy() + shell_env["PATH"] = path_env + shell_env["srctree"] = srctree - lines = subprocess.check_output(args, cwd=os.path.dirname(doc.current_source)).decode('utf-8') + lines = self.runCmd(cmd, shell=True, cwd=cwd, env=shell_env) line_regex = re.compile("^\.\. FILE (\S+)$") @@ -112,6 +121,30 @@ class KernelFeat(Directive): nodeList = self.nestedParse(out_lines, fname) return nodeList + def runCmd(self, cmd, **kwargs): + u"""Run command ``cmd`` and return its stdout as unicode.""" + + try: + proc = subprocess.Popen( + cmd + , stdout = subprocess.PIPE + , stderr = subprocess.PIPE + , **kwargs + ) + out, err = proc.communicate() + + out, err = codecs.decode(out, 'utf-8'), codecs.decode(err, 'utf-8') + + if proc.returncode != 0: + raise self.severe( + u"command '%s' failed with return code %d" + % (cmd, proc.returncode) + ) + except OSError as exc: + raise self.severe(u"problems with '%s' directive: %s." + % (self.name, ErrorString(exc))) + return out + def nestedParse(self, lines, fname): content = ViewList() node = nodes.section() diff --git a/Documentation/translations/zh_CN/arch/loongarch/features.rst b/Documentation/translations/zh_CN/arch/loongarch/features.rst index cec38dda829..82bfac180bd 100644 --- a/Documentation/translations/zh_CN/arch/loongarch/features.rst +++ b/Documentation/translations/zh_CN/arch/loongarch/features.rst @@ -5,4 +5,4 @@ :Original: Documentation/arch/loongarch/features.rst :Translator: Huacai Chen -.. kernel-feat:: features loongarch +.. kernel-feat:: $srctree/Documentation/features loongarch diff --git a/Documentation/translations/zh_CN/arch/mips/features.rst b/Documentation/translations/zh_CN/arch/mips/features.rst index 0d6df97db06..da1b956e4a4 100644 --- a/Documentation/translations/zh_CN/arch/mips/features.rst +++ b/Documentation/translations/zh_CN/arch/mips/features.rst @@ -10,4 +10,4 @@ .. _cn_features: -.. kernel-feat:: features mips +.. kernel-feat:: $srctree/Documentation/features mips